from django.db import models


# Create your models here.

# 后台管理用户
class Seller(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=32)
    pwd = models.CharField(max_length=128)
    email = models.CharField(max_length=32)
    phone = models.CharField(max_length=32)
    address = models.TextField()
    gender = models.BooleanField(default=True)
    image = models.ImageField(upload_to='image')

# 店铺模型类  需要与用户关联
class Store(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=32)
    address = models.TextField()
    desc = models.TextField()
    logo = models.ImageField(upload_to='image')
    seller = models.OneToOneField(to='Seller', on_delete=models.CASCADE)

#  商品模型类
class GoodsType(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=32)
    logo = models.ImageField(upload_to='image')


# 商品模型类  需要与店铺和商品类型关联
class Goods(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=32)
    price = models.DecimalField(max_digits=5, decimal_places=2)
    bzq = models.IntegerField()
    prodate = models.DateField()
    desc = models.CharField(max_length=32)
    details = models.TextField()
    goodsimg = models.ImageField(upload_to='image')
    # 商品和商品类型的关系
    goodsType = models.ForeignKey(to='GoodsType', on_delete=models.CASCADE)
    # 商品和店铺的关系
    store = models.ForeignKey(to='Store',on_delete=models.CASCADE)